<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Document</title>
    <style>
      html,
      body {
        margin: 0;
      }
      .box {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
      }
      .item {
        margin-top: 20px;
        width: 2.6666666666666665rem;
        height: 50px;
        background-color: red;
        color: white;
        line-height: 50px;
        text-align: center;
      }
    </style>
  </head>
  <body style="font-size: 14px">
    <div class="box">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
    </div>

    <script>
      function setFontSize() {
        /*动态计算当前页面的html的font-size*/
        const fontSize = document.documentElement.clientWidth / 10;
        // console.log("fontSize", fontSize);
        document.documentElement.style.fontSize = fontSize + "px";
      }

      // 量出元素的大小 100px ，计算这个元素对应的rem值
      // 元素的rem = 元素设计稿上的大小 / font-size

      // setFontSize();

      window.onload = window.onresize = setFontSize;
    </script>
  </body>
</html>
